<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
//     return $request->user();
// });

Route::any('/test', function () {
  \Log::debug('test: ' . json_encode(request()->all()));
  return 'ok';
});

Route::post('/{role}/login', 'AuthController@login')->name('login');
// Route::post('/register', 'AuthController@register')->name('register');

Route::post('logout', 'AuthController@logout');

Route::post('/sms/code', 'SmsController@sendCode');
Route::post('/sms/code_login', 'SmsController@sendCode');
Route::post('/s/order-sdk', 'OrderController@sdk');
Route::post('/s/order-detail-sdk', 'OrderController@sdkOrderDetail');

// Route::post('refresh', 'AuthController@refresh');


Route::group(['middleware' => ['auth', 'single-login']], function () {
  Route::get('system', 'SystemController@index');
  Route::get('/me', 'AuthController@me');
  Route::post('/password-check', 'AuthController@passwordCheck');

  Route::put('/password/reset', 'PasswordController@reset');

  // Route::get('/auth/refresh', 'AuthController@refresh');
  Route::get('/google-auth/qrcode', 'GaController@qrcode');
  Route::put('/google-auth/bind', 'GaController@bind');
  Route::post('/mobile/bind', 'SmsController@bindMobile');
  // Route::post('/bind', 'UserController@bind');
  Route::get('/info/update', 'AuthController@info');
  Route::get('/profile-info', 'UserController@profileInfo');
  Route::get('/a/callback-buys', 'CallbackController@indexForAdmin');
  Route::post('/a/callback-buys/send', 'CallbackController@send');

  Route::group(['middleware' => 'role:admin',], function () {
    Route::get('/a/dashboard', 'StatisController@dashboardForAdmin');
    Route::get('/a/tiemout-count', 'StatisController@tiemoutCount');
    Route::get('/a/sub-admins', 'AdminController@index');
    Route::put('/a/sub-admins/{id}/perms', 'AdminController@perms');
    Route::put('/a/sub-admins/{id}', 'AdminController@update');
    Route::post('/a/sub-admins/add', 'AdminController@add');
    Route::delete('/a/sub-admins/{id}', 'AdminController@destroy');
    Route::put('/a/password-reset', 'PasswordController@reset2');
    Route::get('/a/logs', 'OprationLogController@index');
    Route::delete('/a/sellers/{id}/ga', 'GaController@destroy');
    Route::delete('/a/whitelist', 'WhitelistController@destroy');
    Route::post('/a/agents/{id}/draw-coins', 'AgentController@drawCoins');

    Route::put('/a/api-switch', 'SystemController@apiSwitchToggle');
    Route::get('/a/api-switch', 'SystemController@apiSwitch');

    Route::get('/a/notice-count', 'StatisController@noticeCount');


    Route::get('/a/agents', 'AgentController@indexForAdmin');
    Route::post('/a/agents', 'AgentController@store');
    Route::put('/a/agents/{id}', 'AgentController@update');
    Route::get('agency-accounts', 'AgentController@accounts');

    Route::put('/a/sells/{sell}/review', 'SellController@review');
    Route::put('/a/sells/{id}/unlock', 'SellController@unlockByAdmin');

    Route::get('/a/sellers', 'SellerController@indexForAdmin');
    Route::get('seller-accounts', 'SellerController@accounts');
    Route::post('sellers', 'SellerController@store');
    Route::put('/a/sellers/{id}', 'SellerController@update');
    Route::put('/a/sellers/{id}/coins', 'SellerController@adjustCoins');
    Route::delete('sellers/{id}', 'SellerController@destroy');

    Route::get('/a/members', 'MemberController@index');
    Route::put('/a/members/{id}', 'MemberController@update');
    Route::get('member-accounts', 'MemberController@accounts');
    Route::put('users/{user}/enable', 'UserController@enable');

    Route::get('/a/buys', 'BuyController@indexForAdmin'); // 买币
    Route::get('/a/buys/timeout', 'BuyController@timeoutIndexForAdmin'); // 买币
    Route::put('/a/buys/{id}/fail', 'BuyController@failByAdmin'); // 买币
    Route::put('/a/buys/{id}/unlock', 'BuyController@unlockByAdmin');

    Route::get('sells', 'SellController@index'); // 卖币

    Route::get('/a/balances', 'BalanceController@indexForAdmin');

    Route::put('system/{system}', 'SystemController@update');
  });

  Route::group(['middleware' => ['role:seller'],], function () {
    Route::put('/s/password-reset', 'PasswordController@reset2');
    Route::put('/s/security-reset', 'PasswordController@resetSecurity');
    Route::post('/s/password/check', 'PasswordController@checkPassword');
    Route::post('/s/security/check', 'PasswordController@checkSecurity');
    Route::get('/s/api-token/generate', 'PasswordController@generateApiToken');
    Route::put('/s/notify_url', 'UserController@setNotifyUrl');

    Route::get('/s/whitelist', 'WhitelistController@index');
    // Route::put('/s/whitelist/{whitelist}', 'WhitelistController@update');
    Route::post('/s/whitelist', 'WhitelistController@store');
    // Route::delete('/s/whitelist/{whitelist}', 'WhitelistController@destroy');

    Route::get('/s/sub-sellers', 'SubSellerController@index');
    Route::put('/s/sub-sellers/{id}/perms', 'SubSellerController@perms');
    Route::put('/s/sub-sellers/{id}', 'SubSellerController@update');
    Route::post('/s/sub-sellers/add', 'SubSellerController@add');
    Route::delete('/s/sub-sellers/{id}', 'SubSellerController@destroy');

    Route::get('/s/dashboard', 'StatisController@dashboardForSeller');
    Route::get('/s/balances', 'BalanceController@indexForSeller');
    Route::get('/s/balances/report', 'BalanceController@reportForSeller');


    Route::get('/s/buys', 'SellController@indexForSeller');
    Route::get('/s/pass-sells', 'SellController@passIndexForSeller');
    Route::get('/s/buys/{id}/lock', 'SellController@lock');
    Route::put('/s/buys/{id}', 'SellController@sold');
    Route::put('/s/buys/{id}/cancel', 'SellController@unlockByAdmin');
    Route::get('/s/sells', 'BuyController@indexForSeller');
    Route::post('/s/orders', 'OrderController@bySeller');
  });

  Route::group(['middleware' => 'role:agent',], function () {
    Route::get('/g/dashboard', 'StatisController@dashboardForAgent');

    Route::get('/g/members', 'MemberController@indexForAgent');
    Route::put('/g/members/{id}', 'MemberController@adjust');
    Route::post('/g/members', 'MemberController@storeByAgent');

    Route::get('/g/buys', 'BuyController@indexForAgent');
    Route::get('/g/sells', 'SellController@indexForAgent');
  });

  Route::group(['middleware' => 'role:member'], function () {
    Route::get('/my/buys', 'BuyController@indexForMember');
    Route::get('/my/buys/statis', 'BuyController@statis');
    // Route::get('/my/buys/deposited', 'BuyController@depositedIndex');
    Route::get('m/buys/{id}', 'BuyController@show');
    Route::put('/buys/{id}/take', 'BuyController@take');
    Route::put('/buys/{id}/finish', 'BuyController@freeze');
    Route::put('/buys/{id}/cancel', 'BuyController@cancel');

    Route::get('/my/sells', 'SellController@indexForMember');
    Route::post('/m/member/sells', 'SellController@store');
    Route::get('/my/sells/statis', 'SellController@statis');

    Route::post('/m/bankcard/add', 'BankcardController@add');
    Route::post('/m/bankcard/add_n', 'BankcardController@addNew');
    Route::delete('/m/bankcards/{id}', 'BankcardController@destroy');

    Route::put('/m/buys/{id}/count-down', 'BuyController@unfreeze');
  });
});
